<?php

namespace app\wxapp\controller;
use think\Request;
use think\Db;


class Api {
	private $token = 'f30173557ee54d6e9c60857ee30889a2';

	public function cars(){
		$request = Request::instance();
		$data = $request->param();
		if($data['token'] != $this->token){
			return [
                'code'=>1,
                'msg'=>'身份不合法'
            ];
		}

		if(!empty($data['car_sn'])){

			if(is_array($data['car_sn'])){
				$data['car_sn'] = array_filter($data['car_sn']);
			}

			try{

				$res = Db::name('cars')->where('car_sn','in',$data['car_sn'])->where(['delete_time'=>null])->limit(10)->field('car_unique_id,car_sn,cardcode')->select();

			}catch(\Exception $e){
				return [
	                'code'=>1,
	                'msg'=>$e->getMessage()
	            ]; 
			}

			if($res){
				return [
					'code'=>0,
					'msg'=>'成功',
					'data'=>$res
				];
			}else{
				return [
	                'code'=>1,
	                'msg'=>'车牌号不存在'
	            ];
			}
			
		}else{
			return [
	            'code'=>2,
	            'msg'=>'车牌号不能为空'
	        ];
		}

		
	}

	public function card(){
		$request = Request::instance();
		$data = $request->param();
		if($data['token'] != $this->token){
			return [
                'code'=>1,
                'msg'=>'身份不合法'
            ];
		}
		try{

			$res = Db::name('cars')->where('sim_id','in',$data['sim_id'])->where(['delete_time'=>null])->limit(10)->field('cardcode,sim_id,equipment_id')->select();

		}catch(\Exception $e){
			return [
                'code'=>1,
                'msg'=>$e->getMessage()
            ];
		}

		if($res){
			return [
				'code'=>0,
				'msg'=>'成功',
				'data'=>$res
			];
		}else{
			return [
                'code'=>1,
                'msg'=>'卡序列号不存在'
            ];
		}
	}
}
